package com.csmzxy.soft.atm;


import com.csmzxy.soft.comm.Status;

public class ATMClient {
	private IATMService atm;
	private ScreenCard  scrCard;
	private ScreenMessage scrMessage;
	private ScreenDeposit scrDeposit;
	private ScreenWithdraw scrWithdraw;
	private ScreenMain scrMain;
	private Screentransfer scrtransfer;
	private ScreenchangePwd scrchangePwd;
	private IScreen screen;
	private IScreen[] screens;
	public ATMClient(){
		atm=new ATMLocalService();
		scrCard=new ScreenCard();
		scrMessage=new ScreenMessage();
		scrDeposit=new ScreenDeposit();
		scrWithdraw=new ScreenWithdraw();
		scrMain=new ScreenMain();
		scrchangePwd=new ScreenchangePwd();
		scrtransfer=new Screentransfer();
		screens=new IScreen[]{
			scrMessage,scrDeposit,scrDeposit,scrWithdraw,scrtransfer,scrchangePwd,scrMessage
		};
	}
	public void work(){		
		Status status;
		String accId;
		do{
			screen=scrCard;
			screen.show();
			status=atm.login(screen.getInput1().getString(),screen.getInput2().getString());
			
		}while(status!=Status.OK);
		accId=screen.getInput1().getString();
		while(true){
			screen=scrMain;
			screen.show();
			int op=screen.getInput1().getInteger();
			if(op==0)break;
			screen=screens[op];
			switch(op){
			case 1:
			double banlance=atm.getBalance(accId);
			screen.show("当前余额："+banlance);
			break;
			case 2:
			screen.show();
			double money=screen.getInput1().getDouble();
			status=atm.deposit(accId, money);
			if(status==Status.OK){
				System.out.println("存款成功！");
			}
			break;
			case 3:
			screen.show();
			money=screen.getInput1().getDouble();
			status=atm.withDraw(accId, money);
			if(status==Status.OK){
				System.out.println("取款成功");
			}else{
				System.out.println("余额不足");
			}
			break;
			case 4:
			screen.show();
			money=screen.getInput2().getDouble();
			String toAccId=screen.getInput1().getString();
			status=atm.transfer(accId, toAccId, money);
			if(status==Status.OK){
				System.out.println("转账成功");
			}else{
				System.out.println("余额不足");
			}
			break;
			case 5:
			screen.show();
			String oldPwd=screen.getInput1().getString();			
			String newPwd=screen.getInput2().getString();			
			status=atm.changePwd(accId, oldPwd, newPwd);
			if(status==Status.OK){
				System.out.println("密码修改成功");
			}else{
				System.out.println("旧密码不正确");
			}
			break;
			case 6:
			String msg=atm.getTransactions(accId);
			System.out.println(msg);
			break;
			}
		}
	}

	public static void main(String[] args) {
		new ATMClient().work();
		System.out.println("程序退出！");

	}


}
